<template>
    <div id="app">
      <keep-alive>
        <router-view v-if="$route.meta.keepAlive"></router-view>
      </keep-alive>
      <!-- 不缓存的页面，不缓存$route.meta.keepAlive为false的组件 -->
      <router-view v-if="!$route.meta.keepAlive"></router-view>
    </div>
</template>

<script>
export default {
    data() {
        return {
            isNavigating: false // 添加导航状态标记
        };
    },
    created() {
        console.log('App created, authentication already initialized in main.js');
        
        // 检查认证状态
        console.log('Current authentication state:', {
            isLoggedIn: this.$store.getters.isLoggedIn,
            username: this.$store.state.myName,
            currentRoute: this.$route.path
        });
        
        // 如果用户已登录且当前在登录页，则重定向到主页
        // 添加导航状态检查，避免重复导航
        if (this.$store.getters.isLoggedIn && this.$route.path === '/login' && !this.isNavigating) {
            console.log('User is logged in and on login page, redirecting to home');
            this.isNavigating = true; // 标记导航开始
            // 使用 replace 而不是 push，避免导航历史堆积
            this.$router.replace('/Main/home').finally(() => {
                this.isNavigating = false; // 导航完成后重置标记
            });
        }
    },
};
</script>

<style scoped>
#app {
    padding: 0px;
    margin: 0px;
    height: 100%;
    font-size: 14px;
    font-family: "Microsoft Yahei", "Avenir", Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
.el-input {
    ::v-deep .el-input__inner {
        &:focus {
            outline: none;
        }
    }
}
body {
    font-family: "PingFang";
}

#app {
    font-family:
            "Helvetica Neue",
            Helvetica,
            Arial,
            "PingFang SC",
            "Hiragino Sans GB",
            "Heiti SC",
            "Microsoft YaHei",
            "WenQuanYi Micro Hei",
            sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
}
</style>
